#include "linux/init.h"
#include "linux/interrupt.h"
#include "linux/of_irq.h"
#include "linux/printk.h"
#include "linux/platform_device.h"

struct of_device_id imx6_i2c_id[] = {
    { .compatible = "test-i2c", .data = 0},
    { .compatible = "fsl,imx6-i2c", .data = NULL, },
	{ /* sentinel */ }
};

irqreturn_t imx6ul_i2c_irq_handler(int virq, void *arg)
{
    printk("%s %d %s\n", __FILE__, __LINE__, __func__);
    return IRQ_HANDLED;
}

int imx6_i2c_probe(struct platform_device *pdev)
{
    int ret;
    int irq;

    printk("%s %d %s\n", __FILE__, __LINE__, __func__);
    
    irq = irq_of_parse_and_map(pdev->dev.of_node, 0);

    ret = request_irq(irq, imx6ul_i2c_irq_handler, IRQF_SHARED | IRQF_TRIGGER_RISING, "imx6-i2c", pdev);
    if (ret)
    {
        printk("Failed to request irq %d for imx6-i2c\n", irq);
        return ret;
    }
    printk("Succeeded to request irq %d for imx6-i2c\n", irq);
    
    return 0;
}

struct platform_driver imx6_i2c_driver = {
    .name = "imx6-i2c",
    .id_table = NULL,
    .probe = imx6_i2c_probe,
    .remove = NULL,
    .driver = {
        .name = "imx6-i2c",
        .of_match_table = imx6_i2c_id,
    },
};


static int imx6_i2c_init_module(void)
{
    int ret;

    printk("%s %d %s\n", __FILE__, __LINE__, __func__);


    ret = platform_driver_register(&imx6_i2c_driver);
    
    return ret;
}

static void imx6_i2c_exit_module(void)
{

}

module_init(imx6_i2c_init_module);
module_exit(imx6_i2c_exit_module);